import logging

from redis import StrictRedis


class Config:
    """配置基类"""
    SECRET_KEY = '123'

    # 配置数据库
    SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:mysql@127.0.0.1:3306/ihome'
    SQLALCHEMY_TRACK_MODIFICATIONS = True

    # 类属性-redis接口
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    # session存储地址
    SESSION_TYPE = 'redis'
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
    SESSION_USE_SIGNER = True
    SESSION_PERMANENT = False
    PERMANENT_SESSION_LIFETIME = 86400

    # log
    LOG_LEVEL = logging.DEBUG


class DevelopConfig(Config):
    """开发环境配置类"""
    DEBUG = True
    ENV = 'development'


class PorductConfig(Config):
    """生产环境配置类"""
    DEBUG = False
    LOG_LEVEL = logging.ERROR


class TestConfig(Config):
    """测试环境配置类"""
    DEBUG = True


# 用字典对配置类进行封装
config = {
    'default': DevelopConfig,
    'develop': DevelopConfig,
    'product': PorductConfig,
    'test': TestConfig,
}
